package com.sure0000.java8;

import org.junit.Test;

import java.util.Arrays;
import java.util.function.Supplier;

/**
 * @author xuyouchang
 * @date 2020/11/3.
 */
public class ReferenceDemo {
    public static ReferenceDemo create(final Supplier<ReferenceDemo> supplier) {
        return supplier.get();
    }

    public static void collide(final ReferenceDemo car) {
        System.out.println("Collided " + car.toString());
    }

    public void follow(final ReferenceDemo another) {
        System.out.println("Following the " + another.toString());
    }

    public void repair() {
        System.out.println("Repaired " + this.toString());
    }

    @Test
    public void demo() {
        // 构造器引用
        ReferenceDemo referenceDemo = ReferenceDemo.create(ReferenceDemo::new);
        // 静态方法引用
        Arrays.asList(referenceDemo).forEach(ReferenceDemo::collide);
        // 普通方法引用
        Arrays.asList(referenceDemo).forEach(ReferenceDemo::repair);

    }
}
